<?php
// 注册控制器
class RegistController extends CommonController{

	public function code(){
		$code = new Code();
		$code->show();
	}

	/**
	 * [check_code 检测验证码是否正确]
	 * @return [type] [description]
	 */
	public function check_code(){
		if(!IS_AJAX) $this->error('非法请求');
		$code = Q('post.code', '', 'strtoupper');
		if($code != session('code')){
			echo 0;
		}else{
			echo 1;
		}
		die;
	}
	public function check_name(){
		if(!IS_AJAX) $this->error('非法请求');
		$name=Q('post.username_reg');
		$name_all=K('User')->get_data();
		if (empty($name_all)) {
			echo 1;
		}else{
			$tempArr=array();
			foreach ($name_all as $v) {
				$tempArr[]=$v['username'];
			}
			$bool=in_array($name, $tempArr);
			if ($bool) {
				echo 0;
			}else{
				echo 1;
			}
		}	
		die;	
	}
	public function ajax_add_data(){
		if(!IS_AJAX) $this->error('非法请求');
		$name=Q('post.username_reg');
		$nickname=Q('post.nickname');
		$password=Q('post.password_reg1');
		$data=array(
            'username'=>$name,
            'nickname'=>$nickname,
            'password'=>md5($password)
		);
		$useData=K('User')->add_data($data);
		if($useData){
			$this->ajax(1,'JSON');
		}else{
			$this->ajax(0,'JSON');
		}			
	}
}










